<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <meta name="renderer" content="webkit">
    <title></title>  
    <link rel="stylesheet" href="css/pintuer.css">
    <link rel="stylesheet" href="css/admin.css">
    <script src="js/jquery.js"></script>
    <script src="js/pintuer.js"></script>  
</head>
<body>
<#if list?exists>
  <div class="panel admin-panel">
    <div class="panel-head"><strong class="icon-reorder">联系方式管理</strong></div>
    <div class="padding border-bottom">
      <ul class="search">
        <li>
          <button type="button"  class="button border-green" id="checkall"><span class="icon-check"></span> 全选</button>
          <button type="submit" class="button border-red" onclick="DelSelect()"><span class="icon-trash-o"></span> 批量删除</button>
        </li>
      </ul>
    </div>
    <table class="table table-hover text-center">
      <tr>
        <th width="120">ID</th>
        <th>姓名</th>       
        <th>电话</th>
        <th>邮箱</th>
        <th width="25%">内容</th>
         <th width="120">更新时间</th>
        <th>操作</th>       
      </tr>
      
      	<#list list as homeContactUs>      
        <tr>
          <td><input type="checkbox" name="id" value="${homeContactUs.id}" />
            ${homeContactUs.id}</td>
          <td>${homeContactUs.name}</td>
          <td>${homeContactUs.phone}</td>
          <td><#if homeContactUs.email??>${homeContactUs.email}</#if></td>  
          <td>${homeContactUs.address}</td>
          <td><#if homeContactUs.email??>${homeContactUs.updated?string('yyyy-MM-dd HH:mm:ss')}</#if></td>
          <td>
		      <div class="button-group">
		          <a type="button" class="button border-main" href="/updateContactUs.html?id=${homeContactUs.id}"><span class="icon-edit"></span>修改</a>
		          <a class="button border-red"  onclick="return del(${homeContactUs.id})"><span class="icon-trash-o"></span> 删除</a> 
	          </div>
          </td>
        </tr>
        </#list>
    </table>
  </div>
<br>
</#if>
<div class="panel admin-panel">
  <div class="panel-head" id="add"><strong><span class="icon-pencil-square-o"></span>增加内容</strong></div>
  <div class="body-content">
    <form method="post" class="form-x" action="/addHomeContactUs.html">  
      <div class="form-group">
        <div class="label">
          <label>标题：</label>
        </div>
        <div class="field">
          <input type="text" class="input w50" name="name" data-validate="required:请输入标题" />
          <div class="tips"></div>
        </div>
      </div>
      
      <div class="form-group">
        <div class="label">
          <label>email：</label>
        </div>
        <div class="field">
          <input type="text" class="input w50" name="email" data-validate="required:请输入标题" />
          <div class="tips"></div>
        </div>
      </div>
      
      <div class="form-group">
        <div class="label">
          <label>phone：</label>
        </div>
        <div class="field">
          <input type="text" class="input w50" name="phone" data-validate="required:请输入标题" />
          <div class="tips"></div>
        </div>
      </div>
      
      <div class="form-group">
        <div class="label">
          <label>描述：</label>
        </div>
        <div class="field">
          <textarea class="input" name="address" style=" height:90px;"></textarea>
          <div class="tips"></div>
        </div>
      </div>
     
      <div class="form-group">
        <div class="label">
          <label>排序：</label>
        </div>
        <div class="field">
          <input type="text" class="input w50" name="state" value="1"  data-validate="number:排序必须为数字" />
          <div class="tips"></div>
        </div>
      </div>
      <div class="form-group">
        <div class="label">
          <label></label>
        </div>
        <div class="field">
          <button class="button bg-main icon-check-square-o" type="submit"> 提交</button>
        </div>
      </div>
    </form>
  </div>
</div>
<script type="text/javascript">

function del(id){
	if(confirm("您确定要删除吗?")){
		console.log(id)
		$.ajax({
			url:"/deleteHomeContactUs.html",
			dateType:'json',
			type:"post",
			data:{
				"id":id
			},success:function(data){
				if(data='ok'){
					location.href="/contactList.html"; 
				}
			}
		});
	}
}

$("#checkall").click(function(){ 
  $("input[name='id']").each(function(){
	  if (this.checked) {
		  this.checked = false;
	  }
	  else {
		  this.checked = true;
	  }
  });
})

function DelSelect(){
	var Checkbox=false;
	var dropIds = new Array();
	 $("input[name='id']").each(function(){
	  if (this.checked==true) {		
		dropIds.push($(this).val());
		Checkbox=true;
	  }
	});
	if (Checkbox){
		var t=confirm("您确认要删除选中的内容吗？");
		if (t==false) return false;
		$.ajax({
			url:"/updateContactState.html",
			dateType:'json',
			type:"post",
			traditional:true,//如果要传递数组必须要此参数
			data:{
				"ids":dropIds,
			},success:function(data){
				if(data='ok'){
					location.href="/contactList.html"; 
				}
			}
		});
	}
	else{
		alert("请选择您要删除的内容!");
		return false;
	}
}

</script>
</body></html>